<template>
	<view class="p20">
		<view class="pt40 flex row-center">
			<z-imgs hide cropper @setImg="editInfo({avatar:$event.id})" ref="img" />
			<button class="u-reset-button" style="background: #0000;" type="default" open-type="chooseAvatar" @click="upImg"
				@chooseavatar="onChooseAvatar">
				<view class="p20 flex">
					<u-avatar :src="$user.avatar_img" size="130" show-level level-icon="camera-fill" />
				</view>
			</button>
		</view>
		<view class="mt70 bg-fff radius20 pl20 pr20">
			<modal ref="name" placeholder="请输入昵称" :value="$user.name" @confirm="editInfo({name:$event})"
				type="nickname" />
			<u-form label-width="auto" inputAlign="right">
				<u-form-item label="昵称" right-icon="arrow-right">
					<u-input v-model="$user.name" @click="$refs.name.open()" disabled placeholder="请输入昵称" />
				</u-form-item>
				<u-form-item label="用户ID" right-icon="">
					<u-input v-model="$user.id" disabled placeholder="" />
				</u-form-item>
				<u-form-item label="手机号" right-icon="arrow-right">
					<u-input :modelValue="$user.mobile1||$user.mobile" disabled placeholder=""
						@click="$jump('/pages/my/bindMobile/bindMobile')" />
				</u-form-item>
				<!-- 实名认证，支付密码,支付密码,微信授权,支付宝授权 -->
				<u-form-item label="注册时间" right-icon="">
					<u-input v-model="$user.create_time" disabled placeholder="" />
				</u-form-item>
				<u-form-item label="实名认证" right-icon="arrow-right">
					<u-input :modelValue="$list('name_auth',$user.is_name_auth)" @click="$jump('autonym')" disabled
						placeholder="" />
				</u-form-item>
				<u-form-item label="支付密码" right-icon="arrow-right">
					<u-input :modelValue="$user.is_trade_pwd==1?'已设置':'未设置'" @click="$jump('payPsd')" disabled
						placeholder="" />
				</u-form-item>
				<!-- #ifdef APP-PLUS -->
				<u-form-item label="微信授权" right-icon="arrow-right">
					<u-input :modelValue="$user.is_wechat_auth==1?'已授权':'未授权'" @click="wx_auth" disabled
						placeholder="" />
				</u-form-item>
				<u-form-item label="支付宝授权" right-icon="arrow-right">
					<u-input :modelValue="$user.is_alipay_auth==1?'已授权':'未授权'" @click="alipay_auth" disabled
						placeholder="" />
				</u-form-item>
				<!-- #endif -->
				<u-form-item label="银行卡绑定" right-icon="arrow-right">
					<u-input :modelValue="$user.is_bank_bind==1?'已绑定':'未绑定'" @click="$jump('/pages/my/set/bindBank')"
						disabled placeholder="" />
				</u-form-item>

			</u-form>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			};
		},
		onShow() {
			// #ifdef APP
			var args = plus.runtime.arguments
			if (args) uni.$emit('authAlipay', args)
			// #endif
		},
		methods: {
			submit() {
				this.$request('/master/my/editInfo', this.form).then(res => {
					this.$msg(res.msg)
					this.$getUser()
					this.$navBack(1, 1000)
				})
			},
			editInfo(params) {
				this.$request('/master/my/editInfo', params).then(res => {
					this.$getUser()
					if (params.name) this.$refs.name.cancel()
				})
			},
			onChooseAvatar(e) {
				this.$refs.img.uploadFile(e.detail.avatarUrl, 'setImg')
			},
			upImg() {
				// #ifndef MP-WEIXIN
				this.$refs.img.upImg('setImg')
				// #endif
			},
			async wx_auth() {
				// #ifndef APP-PLUS
				return this.$msg('只能在app内授权')
				// #endif
				if (this.$user.is_wechat_auth == 1) await this.$showModal('已授权', '是否重新授权')
				uni.login({
					provider: this.provider,
					"onlyAuthorize": true, // 微信登录仅请求授权认证
					success: (res) => {
						this.authWeChat(res)
					}
				})
			},
			authWeChat(params) { //微信授权接口
				this.$request('/master/personal/authWeChat', params).then(res => {
					console.log(res);
					this.$msg(res.msg)
					this.$getUser()
				})
			},
			async alipay_auth() {
				// #ifdef APP-PLUS
				if (this.$user.is_alipay_auth == 1) await this.$showModal('已授权', '是否重新授权')
				let redirect_uri = this.$global.href + '/static/zfb.html'
				let app_id = this.$config.alipay_appid || '2021003173698804'
				let urls =
					`https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=${app_id}&scope=auth_userinfo&redirect_uri=${redirect_uri}`
				urls = encodeURIComponent(urls); //将地址编码成浏览器访问的格式
				let openURL =
					`alipay${plus.os.name == 'Android'?'s':''}://platformapi/startapp?appId=20000067&url=${urls}`
				plus.runtime.openURL(openURL,
					res => {
						uni.showToast({
							title: '本机未检测到对应客户端',
							icon: 'none'
						});
					},
					'com.eg.android.AlipayGphone'
				)
				uni.$off('authAlipay', this.authAlipay)
				uni.$once('authAlipay', this.authAlipay)
				// #endif
				// #ifndef APP-PLUS
				return this.$msg('只能在app内授权')
				// #endif
			},
			authAlipay(args) { //支付宝授权接口
				args = decodeURIComponent(args)
				args = args.split('?')[1]
				let params = JSON.parse(args)
				this.$request('/master/personal/authAlipay', params).then(res => {
					this.$msg(res.msg)
					this.$getUser()
				})
			},
		}
	}
</script>

<style lang="scss">

</style>